package main

// addTwoNumbers 自己写法
func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
	ln := ListNode{0, nil}
	p := &ln
	for l1.Next != nil || l2.Next != nil {
		p.Val += l1.Val + l2.Val
		if p.Val > 9 {
			p.Next = &ListNode{p.Val / 10, nil}
		} else {
			p.Next = &ListNode{0, nil}
		}
		p.Val = p.Val % 10
		if l1.Next != nil {
			l1 = l1.Next
		} else {
			l1.Val = 0
		}
		if l2.Next != nil {
			l2 = l2.Next
		} else {
			l2.Val = 0
		}
		p = p.Next
	}
	if p.Next.Val == 0 {
		p.Next = nil
	}
	return &ln
}
